﻿define(function (require, exports, module) {
    var Config = require('config');
    var m_stage = new Kinetic.Stage({
        container: 'container',
        width: Config.getWidth(),
        height: Config.getHeight()
    });

    exports.draw = function () {
        m_stage.draw();
    };

    exports.add = function (layer) {
        m_stage.add(layer);
    };

    exports.clear = function () {
        m_stage.removeChildren();
    };

    exports.resize = function () {
        m_stage.setWidth(Config.getWidth());
        m_stage.setHeight(Config.getHeight());
    };

    exports.createLayer = function () {
        var layer = new Kinetic.Layer();
        return layer;
    };

    exports.createImage = function (options) {
        var config = $.extend({ width: options.image.width, height: options.image.height }, options);
        var image = new Kinetic.Image(config);
        return image;
    };

    exports.createImageButton = function (options) {
        var btnImage = this.createImage(options);
        btnImage.createImageHitRegion();

        btnImage.on('mouseover', function (e) {
            document.body.style.cursor = 'pointer';
            options.mouseover && options.mouseover(e);
        });

        btnImage.on('mouseout', function (e) {
            document.body.style.cursor = 'default';
            options.mouseout && options.mouseout(e);
        });

        return btnImage;
    };

    exports.createText = function (options) {
        options || (options = {});
        var config = $.extend({
            fontFamily: Config.getFontFamily(),
            fontSize: Config.getFontSize()
        }, options);
        return new Kinetic.Text(config);
    };

    exports.createRect = function (options) {
        options || (options = {});
        var config = $.extend({ width: Config.getWidth(), height: Config.getHeight() }, options);
        return new Kinetic.Rect(config);
    };
});